package Application.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import Reservation.MysqlConnection;

public class CourseRatingDAO {
	static Connection connection = null;
	static ResultSet rs = null;
	
	public static boolean insertCourseRating(int courseID, String rating){
		boolean valid = false;
		String sql = "insert into maincourserating (cuisineID, cuisineRating) values(?,?)";
		PreparedStatement prestate = null;
		try {
					
					
					if(connection!=null){
						connection = MysqlConnection.getConnection();
						prestate = connection.prepareStatement(sql);
							
							prestate = connection.prepareStatement(sql);
							prestate.setInt(1,courseID );
							prestate.setString(2, rating);
							prestate.executeUpdate();
							valid = true;
					}
					else
					{
						System.out.println("**************connection is null******************");
					}
					
						connection.close();
					}
				catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				return valid;
	}
	
	public static ArrayList<String> getCourseRaing(int courseID){
		ArrayList<String> ratingList = new ArrayList<String>();
		Statement statement = null;
		String sql = "select cuisineRating from maincourserating where cuisineID = "+courseID;
		try {
			connection = MysqlConnection.getConnection();
			if(connection!=null){
				statement = connection.createStatement();
				rs = statement.executeQuery(sql);
				while(rs.next()){
					String rating= rs.getNString(1);
					ratingList.add(rating);
					System.out.println(rating);
				}
				
			}
			else
			{
				System.out.println("**************connection is null******************");
			}
			
				connection.close();
			}
		catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ratingList;
		
	}

}
